package com.epower.web.action.epowerkv;

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.List;
import com.epower.base.BaseAction;
import com.epower.bo.epowerkv.EpowerKvService;
import com.epower.dataobject.EpowerKvDO;

@Scope("prototype")
@Component()
public class EpowerKvAction extends BaseAction {
    
	private static final long serialVersionUID = 1L;
	
	/***查询对象 ***/
	private EpowerKvDO query;
	
	/***对象集合 ***/
	private List<EpowerKvDO> epowerKvList;
	
	/*** BO ***/
	private EpowerKvService epowerKvBO;
	
	/***主键***/
	private String keyname;
	
	/***查询对象 ***/
	private EpowerKvDO epowerKv;
	
	/***当前action所在的namespace ***/
	private String namespace="epowerkv";
	/***当前action对应的module ***/
	private String moduleName="EpowerKv";
	
	/***
	 * 列表视图
	 * @return
	 * @throws Exception
	 */
	public String listEpowerKv() throws Exception {
		//初始化查询条件
		if (query == null) {
			query = new EpowerKvDO();
		}
		//查询列表
		epowerKvList = epowerKvBO.getEpowerKvListPageByOption(query);
		pages = this.getPagesList(query.getToPage(), query.getTotalPage());
		return SUCCESS;
	}
	
	/***
	 * 编辑视图
	 * @return
	 * @throws Exception
	 */
	public String viewEditEpowerKv() throws Exception{
		epowerKv=epowerKvBO.getEpowerKvByKeyname(keyname);
		return SUCCESS;
	}
	
	/***
	 * 编辑操作
	 * @return
	 * @throws Exception
	 */
	 
	public String editEpowerKv()throws Exception{
		if(!epowerKvBO.updateEpowerKvByOption(epowerKv)){
		    addActionMessage("编辑失败");
			return SUCCESS;
		}
		addActionMessage("编辑成功");
		return SUCCESS;
	}
	
	/***
	 * 删除操作
	 * @return
	 * @throws Exception
	 */
	public String deleteEpowerKv()throws Exception{
		if(!epowerKvBO.deleteEpowerKvByKeyname(keyname)){
			addActionMessage("删除失败");
			return SUCCESS;
		}
		addActionMessage("删除成功");
		return SUCCESS;
	}
	/***
	 * 添加视图
	 * @return
	 * @throws Exception
	 */
	public String viewAddEpowerKv()throws Exception{
		return SUCCESS;
	}
	
	/***
	 * 添加操作
	 * @return
	 * @throws Exception
	 */
	public String addEpowerKv()throws Exception{
		if(epowerKvBO.addEpowerKv(epowerKv)==null){
			addActionMessage("添加失败");
			return SUCCESS;
		}
		addActionMessage("添加成功");
		return SUCCESS; 
	}
	
	
	
	/*** setter getter start***/
	public EpowerKvDO getQuery() {
		return query;
	}
	public void setQuery(EpowerKvDO query) {
		this.query = query;
	}
	public List<EpowerKvDO> getEpowerKvList() {
		return epowerKvList;
	}
	public void setEpowerKvList(List<EpowerKvDO> epowerKvList) {
		this.epowerKvList = epowerKvList;
	}
	public EpowerKvService getEpowerKvBO() {
		return epowerKvBO;
	}
	@Resource
	public void setEpowerKvBO(EpowerKvService epowerKvBO) {
		this.epowerKvBO = epowerKvBO;
	}
	public String getKeyname() {
		return keyname;
	}
	public void setKeyname(String keyname) {
		this.keyname = keyname;
	}
	public EpowerKvDO getEpowerKv() {
		return epowerKv;
	}
	public void setEpowerKv(EpowerKvDO epowerKv) {
		this.epowerKv = epowerKv;
	}
	public String getNamespace() {
		return namespace;
	}

	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}
	
	public String getModuleName() {
		return moduleName;
	}
	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	/*** setter getter end***/
}

